//
// Description: 414. 第三大的数
// Created by Loading on 2021/10/6.
//

#include <bits/stdc++.h>

using namespace std;

int thirdMax(vector<int> &nums) {
    long long a = LLONG_MIN, b = LLONG_MIN, c = LLONG_MIN;
    for (auto &x : nums) {
        if (x > a) {
            c = b;
            b = a;
            a = x;
        } else if (x < a && x > b) {// 过滤相等情况
            c = b;
            b = x;
        } else if (x < b && x > c) {// 过滤相等情况
            c = x;
        }
    }

    return (int) (c == LLONG_MIN ? a : c);
}

int main() {
    vector<int> nums = {1, 2, 3, 4};
    int res = thirdMax(nums);
    cout << res << endl;

    return 0;
}